﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {
    public class TestTransformTo {
       /**
        * GetTransformToのテスト1
        * 到達不能
        * */
        [Fact]
        public void TestGetTransformTo1 () {
            Node nod1 = new Group ();
            Node nod2 = new Group ();

            Assert.Equal (null, nod1.GetTransformTo (nod2));
        }

        /**
         * GetTransformToのテスト2 
         * 自分 --> 自分
         * */
        [Fact]
        public void TestGetTransformTo2 () {
            Node nod1 = new Group ();
            nod1.Translate (1, 2, 3);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,0,
                                       0,1,0,0,
                                       0,0,1,0,
                                       0,0,0,1};

            Assert.Equal (expected, nod1.GetTransformTo (nod1).Matrix);
        }

        /**
        /**
         * GetTransformToのテスト3 
         * 子 --> 親
         * */
        [Fact]
        public void TestGetTransformTo3 () {
            Group nod1 = new Group (); // 子
            Group nod2 = new Group (); // 親
            nod1.Translate (1, 2, 3);
            nod2.Scale (1, 2, 3);
            nod2.AddChild (nod1);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,1,
                                       0,1,0,2,
                                       0,0,1,3,
                                       0,0,0,1};

            Assert.Equal (expected, nod1.GetTransformTo (nod2).Matrix);
        }

        /**
         * GetTransformToのテスト4
         * 親 --> 子
         * */
        [Fact]
        public void TestGetTransformTo4 () {
            Group nod1 = new Group (); // 子
            Group nod2 = new Group (); // 親
            nod1.Translate (1, 2, 3);
            nod2.Scale (1, 2, 3);
            nod2.AddChild (nod1);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,-1,
                                       0,1,0,-2,
                                       0,0,1,-3,
                                       0,0,0,1};

            Assert.Equal (expected, nod2.GetTransformTo (nod1).Matrix);
        }

        /**
         * GetTransformToのテスト5
         * 子 --> 子
         * */
        [Fact]
        public void TestGetTransformTo5 () {
            Group nod1 = new Group (); // 子
            Group nod2 = new Group (); // 子
            Group nod3 = new Group (); // 親
            nod1.Scale (1, 2, 3);
            nod2.Translate (1, 2, 3);
            nod3.Translate (2, 2, 2);
            nod3.AddChild (nod1);
            nod3.AddChild (nod2);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,-1,
                                       0,2,0,-2,
                                       0,0,3,-3,
                                       0,0,0,1};

            Assert.Equal (expected, nod1.GetTransformTo (nod2).Matrix);
        }

        /**
         * GetTransformToのテスト6
         * 子 --> 親 --> 祖父
         * */
        [Fact]
        public void TestGetTransformTo6 () {
            Group nod1 = new Group (); // 祖父
            Group nod2 = new Group (); // 親
            Group nod3 = new Group (); // 子
            nod1.Translate (2, 2, 2);
            nod2.Translate (1, 2, 3);
            nod3.Scale (1, 2, 3);
            nod1.AddChild (nod2);
            nod2.AddChild (nod3);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,1,
                                       0,2,0,2,
                                       0,0,3,3,
                                       0,0,0,1};

            Assert.Equal (expected, nod3.GetTransformTo (nod1).Matrix);
        }

        /**
         * GetGlobalTransformのテスト
         * */
        [Fact]
        public void TestGetGlobalTransform () {
            Group nod1 = new Group (); // 祖父
            Group nod2 = new Group (); // 親
            Group nod3 = new Group (); // 子
            nod1.Translate (2, 2, 2);
            nod2.Translate (1, 2, 3);
            nod3.Scale (1, 2, 3);
            nod1.AddChild (nod2);
            nod2.AddChild (nod3);

            var tra = new Transform ();
            var expected = new float[]{1,0,0,3,
                                       0,2,0,4,
                                       0,0,3,5,
                                       0,0,0,1};

            Assert.Equal (expected, nod3.GetGlobalTransform.Matrix);
        }
    }
}
